package com.rc.saas.tenant.service.tenant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.mapper.tenant.TenantCompanyInfoMapper;
import com.rc.saas.tenant.model.tenant.TenantCompanyInfo;
import com.rc.saas.tenant.model.tenant.TenantCompanyInfoExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author frog
 * @date 2021/12/18
 */
@Service
public class TenantCompanyInfoServiceImpl implements TenantCompanyInfoService {

    @Autowired
    private TenantCompanyInfoMapper tenantCompanyInfoMapper;

    @Override
    public TenantCompanyInfoMapper getMapper() {
        return tenantCompanyInfoMapper;
    }

    @Override
    public PageInfo<TenantCompanyInfo> listPageTenantCompanyInfo(BaseSearch baseSearch) {
        PageHelper.startPage(baseSearch.getOffset(), baseSearch.getLimit());
        TenantCompanyInfoExample example = new TenantCompanyInfoExample();
        example.createCriteria().andCompanyTypeEqualTo("1").andTenantCodeEqualTo(baseSearch.getTenantCode());
        List<TenantCompanyInfo> tenantCompanyInfos = tenantCompanyInfoMapper.selectByExample(example);
        return new PageInfo<TenantCompanyInfo>(tenantCompanyInfos);
    }

    @Override
    public List<TenantCompanyInfo> listByTenantCode(String tenantCode) {
        TenantCompanyInfoExample example = new TenantCompanyInfoExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode);
        List<TenantCompanyInfo> tenantCompanyInfos = tenantCompanyInfoMapper.selectByExample(example);
        return tenantCompanyInfos;
    }
}
